<template>
  <div class="divBox">
    <el-card class="box-card">
      <template v-slot:header>
        <div class="clearfix">
        <div class="container">
          <el-form size="small" label-width="100px">
            <el-form-item label="时间选择：" class="width100">
              <el-radio-group
                v-model="tableFrom.dateLimit"
                type="button"
                class="mr20"
                size="small"
                @change="selectChange(tableFrom.dateLimit)"
              >
                <el-radio-button v-for="(item, i) in fromList.fromTxt" :key="i" :label="item.val">{{
                  item.text
                }}</el-radio-button>
              </el-radio-group>
              <el-date-picker
                v-model="timeVal"
                value-format="YYYY-MM-DD"
                format="YYYY-MM-DD"
                size="small"
                type="daterange"
                placement="bottom-end"
                placeholder="自定义时间"
                style="width: 250px"
                @change="onchangeTime"
              />
            </el-form-item>
            <el-form-item label="用户信息" class="width100">
              <el-input v-model="tableFrom.userKeywords" placeholder="会员ID/手机号码/微信昵称" style="width: 370px;" size="small" clearable />
            </el-form-item>
            <el-form-item label="订单信息" class="width100">
              <el-input v-model="tableFrom.orderKeywords" placeholder="订单号/商品名称" style="width: 370px;" size="small" clearable />
            </el-form-item>
            <el-form-item label="交易类型">
              <el-select v-model="tableFrom.tradeType" style="width: 390px;padding-right: 20px;" size="small" clearable placeholder="请选择">
                <el-option v-for="item in tradeTypeOptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
              <el-button  type="primary" size="small" @click="getList" >查询</el-button>
            </el-form-item>           
          </el-form>
        </div>
      </div>
      </template>

      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        highlight-current-row
      >
        <el-table-column prop="uid" label="会员ID" width="80"  align="center" />
        <el-table-column prop="phone" label="手机号码" min-width="80"  align="center" />
        <el-table-column prop="nickname" label="微信昵称" min-width="80"  align="center" />
        <el-table-column prop="orderId" label="订单号" min-width="120"  align="center" />
        <!-- <el-table-column prop="productId" label="商品ID" min-width="80"  align="center" /> -->
        <el-table-column prop="productName" label="商品名称" min-width="120"  align="center" />
        <el-table-column prop="tradeType" label="交易类型" min-width="80"  align="center" >
          <template #default="{row}">
            <div v-if="row.tradeType == 'pay_product_refund'">
              <span 
                >已退款</span
              >
            </div>
            <div v-else>
              <span 
                >已支付</span
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="tradeCash" label="交易现金" min-width="80"  align="center" />
        <el-table-column label="余额变动" min-width="120"  align="center">
          <template #default="{row}">
            <div>
              <span :class="row.tradeType == 'pay_product_refund' ? 'color_green' : 'color_red'"
                >{{ row.tradeType == 'pay_product_refund' ? '+' : '-' }}{{ row.tradeBalance }}</span
              >
            </div>

          </template>
        </el-table-column>
       
        <el-table-column prop="balance" label="余额" min-width="60"  align="center" />
        <el-table-column prop="gainIntegral" label="新增积分" min-width="80"  align="center" />
        <el-table-column prop="increaseIntegral" label="减少积分" min-width="80"  align="center" />
        <el-table-column label="积分变动" min-width="80"  align="center">
          <template #default="{row}">
            <span :class="row.tradeType == 'pay_product_refund' ? 'color_red' : 'color_green'"
                >{{ row.gainIntegral - row.increaseIntegral }}</span
              >
          </template>
        </el-table-column>
        
        <el-table-column prop="integral" label="积分余额" min-width="80"  align="center" />
        <el-table-column prop="tradeTime" label="交易时间" min-width="120"  align="center" /> 
        <el-table-column prop="mark" label="备注" min-width="200" />
        <!-- <el-table-column prop="createTime" label="创建时间" min-width="150" /> -->
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[10,20, 50, 100]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script>
import { monitorListApi, monitorListOptionApi } from '@/api/shopping/financial';
export default {
  name: 'AccountsCapital',
  data() {
    return {
      timeVal: [],
      tableData: {
        data: [],
        total: 0,
      },
      listLoading: true,
      tableFrom: {
        title: '',
        keywords: '',
        dateLimit: '',
        userKeywords: '',
        orderKeywords: '',
        tradeType:'',
        page: 1,
        limit: 10,
      },
      categoryId: '',
      fromList: this.$constants.fromList,
      tradeTypeOptions: [
        { value: 'pay_product_refund', label: '已退款' },
        { value: 'pay_order', label: '已支付' },
      ],
      options: [
        // { value: 'recharge', label: '充值支付' },
        // { value: 'admin', label: '后台操作' },
        { value: 'productRefund', label: '商品退款' },
        { value: 'payProduct', label: '购买商品' },
      ],
    };
  },
  mounted() {
    // this.getTypes()
    this.getList();
  },
  methods: {
    selectChange(tab) {
      this.tableFrom.dateLimit = tab;
      this.timeVal = [];
      this.tableFrom.page = 1;
      this.getList();
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e;
      this.tableFrom.dateLimit = e ? this.timeVal.join(',') : '';
      this.tableFrom.page = 1;
      this.getList();
    },
    // 列表
    getList() {
      this.listLoading = true;
      monitorListApi(this.tableFrom)
        .then((res) => {
          this.tableData.data = res.data.list;
          this.tableData.total = res.data.total;
          this.listLoading = false;
        })
        .catch((res) => {
          ElMessage.error(res.message);
          this.listLoading = false;
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList();
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList();
    },
    selectType(e) {
      this.getList();
    },
  },
};
</script>

<style scoped>
.selWidth {
  width: 300px;
}
.color_red {
  color: #f5222d;
}
.color_green {
  color: #7abe5c;
}
</style>
